package com.day12me;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
//本类用于演示双向单次
public class Test2 {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost", 8877);
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            bw.write("你好，大哥，这里是客户端，我开始向你发送消息");
            bw.flush();
            socket.shutdownOutput();
            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String answer =br.readLine();
            System.out.println(answer);

            br.close();
            socket.close();


        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
